﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using Shpm.App.Commons.Utils;
using Shpm.App.Input.Bean;
using Shpm.System;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Third.Dao;

public partial class App_Input_UrgencyForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Ajax.Utility.RegisterTypeForAjax(typeof(CommonAjaxUtils), this.Page);

        if(!IsPostBack)
        {
           
            this.GridView1.DataSource = FindAlarm();
            this.GridView1.DataBind();
            this.GridView1.PageIndex = 0;
        }

    }
    private IList FindAlarm()
    {
        AlarmDao dao = new AlarmDao();
        IList list = dao.FindUserAlarmHisRec();
        //AlarmBean bean = null;
        //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "d:\\IAlarmDB.mdb; Jet OLEDB:Database Password=8199 ";//ACCESS链接字符串 
        //OleDbConnection ConnAcc = new OleDbConnection(strConn); //OleDb链接类的实例化 
        //ConnAcc.Open();//打开数据库 
        //string strSQL = "SELECT * FROM UserAlarmHisRec ORDER BY BeginTime DESC";//SQL语句 
        //OleDbCommand cmd = new OleDbCommand(strSQL, ConnAcc);//创建Command命令对象 
        //OleDbDataReader dr = cmd.ExecuteReader();//创建DataReader对象，并调用ExecuteReader从数据源检索行 
        //while (dr.Read())
        //{
        //    bean = new AlarmBean();
        //    bean.UserID = dr["UserID"].ToString().Replace("#", "号楼") + "室";
        //    bean.BeginTime = dr["BeginTime"].ToString();
        //    bean.EndTime = dr["EndTime"].ToString();
        //    bean.Comments = dr["Comments"].ToString();
        //    list.Add(bean);

        //}
        return list;
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        string sendFlg = this.hidSendFlg.Value;
        if("TRUE".Equals(sendFlg))
        {
            SendMessage("报警事件--", "7101");
            ((Design_MasterPage)this.Master).InfoMessage = "发送成功！";
            this.hidSendFlg.Value = "FALSE";
        }

    }
    //send message
    private void SendMessage(string subject, string toEmployeeId)
    {
        SysUserManager manager = new SysUserManager(Context);
        SysUserBean sysUserBean = manager.getSysUserBean();
        MstSysUserBean mstSysUserBean =
            sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
        MstEmployeeBean mstEmpBean =
            sysUserBean == null ? null : sysUserBean.getEmployeeBean();
        string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
        string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;


 
        MessageBean beanMsg = new MessageBean();
        beanMsg.Subject = subject + DateTime.Now.ToString();
        beanMsg.Message = this.hidUserID.Value +"("+this.hidBeginTime.Value+")："+this.hidComments.Value;
        beanMsg.MessageType = 1;
        beanMsg.SendDate = DateTime.Now;
        beanMsg.ReplyFlag = false;
        beanMsg.ReaderHistoryFlag = false;
        beanMsg.ImportantFlag = false;
        beanMsg.EmployeeId = emplyId;
        beanMsg.UserId = loginId;
        CommonSendMessageUtils sendMsg = new CommonSendMessageUtils(beanMsg, toEmployeeId);
        sendMsg.SendMessage();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        this.GridView1.DataSource = FindAlarm();
        this.GridView1.DataBind();
    }
}
